<template>
	<scroll-view class="goods-scroll-box" scroll-x="true">
		<view class="goods-card" v-for="(goods,index) in goodsData" :key="goods.shop_id" @click="toDetail(goods.shop_id)">
			<image class="card-img" :src="imageUrl + goods.cover_image" mode="aspectFill"></image>
			<view class="card-right">
				<text class="title">{{goods.title}}  |  {{goods.subtitle}}</text>
				<text class="description">{{goods.description}}</text>
				<view class="price-box">
					<text class="price">￥{{goods.display_price}}</text>
					<text class="suffix">/起</text>
				</view>
			</view>
		</view>
	</scroll-view>
</template>

<script setup>
	import {ref,watchEffect} from 'vue'
	// import {onLoad} from '@dcloudio/uni-app'
	import {imageUrl} from '@/config/request/request.js'
	import { getAttractionsGoods } from '@/config/API/Map.js';
	import {routerGuard} from '@/config/RouteGuard.js'
	
	const goodsData = ref([])
	const props = defineProps({
		id: {
			type: Number,
			default: 0,
			required: true
		},
	});
	watchEffect(async() => {
		console.log('父组porps.id:', props.id);
		try {
			const resdata = await getAttractionsGoods(props.id)
			goodsData.value = resdata.data
			console.log('goodsData.value',goodsData.value);
		} catch (error) {
			console.log('获取数据失败',error);
		}
	});
	const toDetail = (id) =>{
		const url = `/homeSubpages/ProductDetails/index?ShopId=${id}`;
		routerGuard(url);
	}
</script>

<style lang="scss" scoped>
	.goods-scroll-box{
		width: 100%;
		max-height: 300rpx;
		white-space: nowrap;
		.goods-card{
			width: 80%;
			height: 240rpx;
			display: inline-flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx 24rpx;
			box-sizing: border-box;
			border-radius: 20rpx;
			background-color: #fff;
			margin-left: 30rpx;
			.card-img{
				min-width: 40%;
				max-width: 40%;
				height: 100%;
				border-radius: 10rpx;
			}
			.card-right{
				min-width: 56%;
				max-width: 56%;
				height: 220rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				text{
					display: -webkit-box;
					-webkit-box-orient: vertical;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: pre-wrap;
				}
				.title{
					-webkit-line-clamp: 2;
					line-height: 52rpx;
					font-weight: 600;
				}
				.description{
					-webkit-line-clamp: 1;
					font-size: 26rpx;
					color: #8a8a8a;
					// margin: 20rpx 0;
				}
				.price-box{
					text{
						display: inline;
						line-height: 52rpx;
					}
					.price{
						font-weight: 600;
						margin-right: 10rpx;
					}
					.suffix{
						color: #8a8a8a;
						font-size: 18rpx;
					}
				}
			}
		}
	}
</style>